
/**
 * 修改
 * @param self
 * @param tiyData
 */
export const showEdit = (self, tiyData,index) => {
  let payment=tiyData.tData.paymentAccountList[index];
  tiyData.tData.paymentAccount.id=payment.id;
  tiyData.tData.paymentAccount.platform=payment.platform;
  tiyData.tData.paymentAccount.name=payment.name;
  tiyData.tData.paymentAccount.fixedPoundage = payment.fixedPoundage;
  tiyData.tData.paymentAccount.poundageRate = payment.poundageRate;
  self.selectChange(payment.platform);
  self.tData.disable=true;
  let params={
    id: payment.id,
  }
  self.$apiOther.queryPaymentAccountById(params)
      .then(function (response) {
        if (response.success) {
          let result=response.result;
            tiyData.tData.paymentAccount.account=result.account;
            tiyData.tData.paymentAccount.mode=result.mode;
            tiyData.tData.paymentAccount.merchantId=result.merchantId;
            tiyData.tData.paymentAccount.publicKey = result.publicKey;
            tiyData.tData.paymentAccount.privateKey = result.privateKey;
            tiyData.tData.paymentAccount.clientId = result.clientId;
            tiyData.tData.paymentAccount.clientSecret = result.clientSecret;
            tiyData.tData.paymentAccount.apiKey = result.apiKey;
            tiyData.tData.paymentAccount.site = result.site;
            tiyData.tData.paymentAccount.stateStatus= result.state==1?true:false;
            tiyData.tData.paymentAccount.note = result.note;
            tiyData.tData.paymentAccount.minPaymentAmount = result.minPaymentAmount;
            tiyData.tData.paymentAccount.maxPaymentAmount = result.maxPaymentAmount;
        } else {
          self.$Message.error(response.errorMessage);
        }
      });

      tiyData.tStatus.modalAdd.isShow=true;
};



//添加
export const addItem = function (self, tiyData, name) {
  tiyData.tStatus.modalAdd.isLoading = true;
  self.$refs[name].validate((valid) => {
    if (valid) {
      let params = {
        id: tiyData.tData.paymentAccount.id,
        platform: tiyData.tData.paymentAccount.platform,
        name:tiyData.tData.paymentAccount.name,
        account:tiyData.tData.paymentAccount.account,
        mode:tiyData.tData.paymentAccount.mode,
        site:tiyData.tData.paymentAccount.site,
        state:tiyData.tData.paymentAccount.stateStatus==true?1:0,
        merchantId:tiyData.tData.paymentAccount.merchantId,
        publicKey:tiyData.tData.paymentAccount.publicKey,
        privateKey:tiyData.tData.paymentAccount.privateKey,
        clientId:tiyData.tData.paymentAccount.clientId,
        clientSecret:tiyData.tData.paymentAccount.clientSecret,
        apiKey:tiyData.tData.paymentAccount.apiKey,
        note:tiyData.tData.paymentAccount.note,
        fixedPoundage:tiyData.tData.paymentAccount.fixedPoundage,
        poundageRate:tiyData.tData.paymentAccount.poundageRate,
        minPaymentAmount:tiyData.tData.paymentAccount.minPaymentAmount,
        maxPaymentAmount:tiyData.tData.paymentAccount.maxPaymentAmount
      };
      self.$apiOther.savePaymentAccount(params).then(response => {
        changeModelLoading(self, tiyData);
        if (response.success) {
          self.$Message.success("保存成功!");
          tiyData.tStatus.modalAdd.isShow = false;
          self.search();
        } else {
          self.$Message.error(response.errorMessage);
        }
      });
    }else {
      changeModelLoading(self, tiyData);
    }
  });
};

//查询列表
export const webList = (self, tiyData) => {
  self.$Spin.show();
  self.$ySpliceAll(tiyData.tData.paymentAccountList);

  let param = {
    "pageSize": tiyData.tPage.stepNumber,
    "pageNum": tiyData.tPage.currentPage,
    "platform": tiyData.tParam.platform,
    "siteCode": tiyData.tParam.siteCode,
  };

  self.$apiOther.queryPaymentAccount(param).then(function (response) {
    if(response.success){
      let payment = response.result;
      tiyData.tPage.total = payment.total;
      tiyData.tPage.stepNumber = payment.pageSize;
      payment.list.forEach(
        function (item) {
          tiyData.tData.paymentAccountList.push(item);
        }
      );
    }else{
      self.$Message.error(response.errorMessage);
    }
    self.$Spin.hide();
  });
};


function changeModelLoading(self, tiyData) {
  tiyData.tStatus.modalAdd.isLoading = false;
  self.$nextTick(function () {
    tiyData.tStatus.modalAdd.isLoading = true;
  });
}
